<?php


namespace app\api\model;


class SubjectAnalogError extends BaseModel
{
    protected $pk = 'false_id';

    protected $autoWriteTimestamp = true;

    public function subject(){
        return $this->belongsTo('SubjectCourse','c_id','c_id');
    }

    /**
     * 添加模拟错题
     * @param $data
     * @return false|int
     */
    public  function addError($data){
        return self::insertAll($data);
    }

    /**
     * 获取模拟错题
     * @param $user_id
     * @param $course
     * @param $car_status
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public  function getAnalogError($user_id,$course,$car_status){
        return self::where('user_id','=',$user_id)
            ->where('course','=',$course)
            ->where('car_status','=',$car_status)
            ->with(['subject'])
            ->select();
    }

    /**
     * 删除用户错题
     * @param $false_id
     * @return int
     */
    public function deleteError($false_id){
        return self::where('false_id','=',$false_id)->delete();
    }

}